package com.leilei.join.common;

import cn.hutool.core.util.RandomUtil;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

/**
 * @author lei
 * @version 1.0
 * @date 2021/3/27 16:52
 * @desc 车辆类型数据源
 */
public class VehicleTypeSource implements SourceFunction<Tuple2<Integer, String>> {
    private String[] vehicleTypes = new String[]{"保时捷卡宴", "路虎揽胜", "阿斯顿马丁"};

    @Override
    public void run(SourceContext<Tuple2<Integer, String>> ctx) throws Exception {
        while (true) {
            int i = RandomUtil.randomInt(1, 4);
            ctx.collect(Tuple2.of(i, vehicleTypes[i - 1]));
            Thread.sleep(1000);
        }
    }

    @Override
    public void cancel() {

    }
}